package com.example.healthmanagement.controller;


import com.example.healthmanagement.entity.AjaxResult;
import com.example.healthmanagement.entity.SportRem;
import com.example.healthmanagement.entity.vo.SportRemVo;
import com.example.healthmanagement.service.SportRemService;
import com.example.healthmanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/sportrem")
public class SportRemController {

    @Autowired
    private SportRemService sportRemService;

    @GetMapping("")
    public List<SportRemVo> getAll(String name) {
        return sportRemService.findAll(name);
    }

    @PostMapping("")
    public boolean save(@RequestBody SportRem data) {
        data.setCreatedAt(LocalDateTime.now());
        data.setDeleted(false);
        return sportRemService.add(data);
    }

    @PutMapping("")
    public boolean update(@RequestBody SportRem data) {
        return sportRemService.update(data);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") int id) {
        SportRem data = sportRemService.findSportRemById(id);
        data.setDeleted(true);
        return sportRemService.update(data);
    }

    @PostMapping("/getSportRemByCid")
    public SportRem getSportRemByChildId(@RequestBody int childId) {
        SportRem sportRem = sportRemService.getSportRemByChildId(childId);
        if (sportRem == null) {
            return null;
        } else {
            return sportRem;
        }
    }

    @PostMapping("/getSportRemByBmi")
    public SportRem getSportRemByCidNoEnergy(@RequestBody double bmi) {
        SportRem sportRem = sportRemService.getSportRemByBmi(bmi);
        if (sportRem == null) {
            return null;
        } else {
            return sportRem;
        }
    }
}
